package com.hex.ds.hdrs.cron.controller;

import com.hex.bigdata.hbda.annotation.Log;
import com.hex.bigdata.hbda.base.Page;
import com.hex.ds.hdrs.common.page.PageData;
import com.hex.ds.hdrs.cron.dto.CronTaskDto;
import com.hex.ds.hdrs.cron.po.CronTask;
import com.hex.ds.hdrs.cron.service.CronTaskReRunService;
import com.hex.ds.hdrs.cron.service.CronTaskService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 定时任务实例表 前端控制器
 * </p>
 *
 * @author ${zuoguichen}
 * @since 2020-11-26
 */
@Slf4j
@RestController
@RequestMapping("/api/cronTask")
public class CronTaskController {

    @Autowired
    private CronTaskService cronTaskService;
    @Autowired
    private CronTaskReRunService cronTaskReRunService;

    /**
     * 查询任务实例信息
     *
     * @return
     */
    @GetMapping
    @ApiOperation("查询定时任务实例")
    public ResponseEntity<Object> qryJobDefPage(CronTaskDto cronTask, Page page) {
        PageData data = new PageData(this.cronTaskService.qryJobDefPage(cronTask, page), page);
        return new ResponseEntity<>(data, HttpStatus.OK);
    }

    @Log("任务批量重跑")
    @ApiOperation("任务批量重跑")
    @PostMapping(value = "/reRunTask")
    public ResponseEntity<Object> reRunTask(@RequestBody List<String> pkIds) {
        log.debug("任务批量重跑【CronTaskController.reRunTask】参数：{}", StringUtils.join(pkIds, ","));
        this.cronTaskReRunService.reRunTask(pkIds);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
